package com.wgts.wgts.mvp.view.activity.guessing;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.wgts.wgts.R;

import com.wgts.wgts.netmodle.resp.GuessingAndAwardOrderEntity;
import com.wgts.wgts.tools.AppInfor;
import com.wgts.wgts.tools.MoHuGlide;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import de.hdodenhof.circleimageview.CircleImageView;

/*
 *
 *
 *   data:2018/10/1310:18
 *
 *   订单子Adapter
 *
 */public class GuessingOrderChildAdapter extends RecyclerView.Adapter<GuessingOrderChildAdapter.ViewHold> {
    private Context context;
    private List<GuessingAndAwardOrderEntity.Product> list;
    private boolean isFirst = true;
    //0 ， 1
    private int type;
    //0  1， 我参与的 2
    private int joinType;

    public GuessingOrderChildAdapter(Context context, List<GuessingAndAwardOrderEntity.Product> list, int type, int joinType) {
        this.context = context;
        this.list = list;
        this.type = type;
        this.joinType = joinType;
    }


    @NonNull
    @Override
    public ViewHold onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        return new ViewHold(LayoutInflater.from(context).inflate(R.layout.guessing_order_item, viewGroup, false));
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHold viewHold, final int i) {
        viewHold.orderButtonLy.setBackgroundResource(R.drawable.guessing_join_border);
        MoHuGlide.getInstance().glideImg(context, list.get(i).productSmallImage, viewHold.goodsImage);
        viewHold.orderNumber.setText(list.get(i).shareCode);
        viewHold.goodsName.setText(list.get(i).productName);
        viewHold.goodsPrice.setText(list.get(i).productPrice);
        viewHold.orderDay.setText(list.get(i).shareDateTime);
        //ACTIVE：进行中，UNOPENED：满员未开奖，OPENED：已开奖，INVALID：已过期
        switch (list.get(i).status) {
            case "ACTIVE":
                viewHold.loseView.setVisibility(View.GONE);
                viewHold.orderType.setText("竞猜中");
                //按钮图标
                viewHold.orderButtonLy.setVisibility(View.GONE);
                //进度文字
                viewHold.orderAwardProgressText.setVisibility(View.VISIBLE);
                viewHold.orderAwardProgressText.setTextColor(ContextCompat.getColor(context, R.color.black));
                viewHold.orderAwardProgressText.setText("进度" + list.get(i).userCount + "/" + list.get(i).drawNumber);
                //中奖人文字
                viewHold.orderAwardText.setVisibility(View.GONE);
                //中奖人的头像
                viewHold.orderAwardPeopleImage.setVisibility(View.GONE);
                break;
            case "UNOPENED":
                viewHold.loseView.setVisibility(View.GONE);
                viewHold.orderType.setText("等待开奖");
                viewHold.orderButtonLy.setVisibility(View.GONE);

                viewHold.orderAwardProgressText.setText("进度" + list.get(i).userCount + "/" + list.get(i).drawNumber);
                viewHold.orderAwardProgressText.setVisibility(View.GONE);
                viewHold.orderAwardText.setVisibility(View.GONE);
                viewHold.orderAwardPeopleImage.setVisibility(View.GONE);
                break;
            case "OPENED":
                viewHold.loseView.setVisibility(View.GONE);
                viewHold.orderType.setText("已开奖");
                viewHold.orderButtonLy.setVisibility(View.GONE);
                viewHold.orderAwardProgressText.setVisibility(View.GONE);
                viewHold.orderAwardText.setVisibility(View.VISIBLE);
                viewHold.orderAwardPeopleImage.setVisibility(View.VISIBLE);
                viewHold.orderAwardText.setText("中奖者:" + list.get(i).winnerUserNickName);
                MoHuGlide.getInstance().glideImg(context, list.get(i).winnerUserImage, viewHold.orderAwardPeopleImage);
                break;
            case "INVALID":
                viewHold.loseView.setVisibility(View.VISIBLE);
                viewHold.orderType.setText("已经失效");
                viewHold.orderButtonLy.setVisibility(View.GONE);
                viewHold.orderAwardProgressText.setVisibility(View.VISIBLE);
                viewHold.orderAwardText.setVisibility(View.GONE);
                viewHold.orderAwardPeopleImage.setVisibility(View.GONE);
                viewHold.orderAwardProgressText.setTextColor(ContextCompat.getColor(context, R.color.logistics_text));
                viewHold.orderAwardProgressText.setText("进度" + list.get(i).userCount + "/" + list.get(i).drawNumber);
                break;
        }

        viewHold.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
//                Intent intent = new Intent(context, MoreMoreGoodInfoActivity.class);
//                intent.putExtra(MoreMoreGoodInfoActivity.DRAWID, list.get(i).shareId);
//                intent.putExtra(MoreMoreGoodInfoActivity.TYPE, MoreMoreGoodInfoActivity.GUESS_ORDER);
//
//                ((Activity) context).startActivityForResult(intent, 0);
            }
        });

    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    public class ViewHold extends RecyclerView.ViewHolder {
        @BindView(R.id.order_number)
        TextView orderNumber;
        @BindView(R.id.order_type)
        TextView orderType;
        @BindView(R.id.goods_image)
        ImageView goodsImage;
        @BindView(R.id.goods_name)
        TextView goodsName;
        @BindView(R.id.place_holder_view)
        TextView placeHolderView;
        @BindView(R.id.goods_price)
        TextView goodsPrice;
        @BindView(R.id.order_day)
        TextView orderDay;
        @BindView(R.id.order_time)
        TextView orderTime;
        @BindView(R.id.order_award_text)
        TextView orderAwardText;
        @BindView(R.id.order_award_people_image)
        CircleImageView orderAwardPeopleImage;
        @BindView(R.id.order_award_progress_text)
        TextView orderAwardProgressText;
        @BindView(R.id.order_button_text)
        TextView orderButtonText;
        @BindView(R.id.order_button_ly)
        RelativeLayout orderButtonLy;
        @BindView(R.id.lose_view)
        LinearLayout loseView;
        private View itemView;

        public ViewHold(@NonNull View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
            this.itemView = itemView;
        }
    }

}
